<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="平方" onclick="f()">
<h3>
    结果:<span></span>
</h3>

<script>
    let i = document.querySelector("input");
    let s = document.querySelector("span");
    function f(){
        if(isNaN(i.value)){
            s.innerText = "输入错误";
            return;
        }
        //s.innerText = i.value*i.value;
        //字符串在进行-*/运算时会自动转成数值类型,而+不会,会当成字符串进行拼接
        //s.innerText = i.value+i.value;
        s.innerText = parseFloat(i.value)+parseFloat(i.value);
    }
</script>


</body>
</html>